# -*- Python -*-

# Configuration file for the 'lit' test runner.

import os
import shlex

import lit.formats

# name: The name of this test suite.
config.name = 'lldb-Suite'

# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.py']

# test_source_root: The root path where tests are located.
# test_exec_root: The root path where tests should be run.
config.test_source_root = os.path.join(config.lldb_src_root, 'packages',
                                       'Python', 'lldbsuite', 'test')
config.test_exec_root = config.test_source_root

# macOS flags needed for LLDB built with address sanitizer.
if 'Address' in config.llvm_use_sanitizer and \
   'Darwin' in config.host_os and \
   'x86' in config.host_triple:
  import subprocess
  resource_dir = subprocess.check_output(
    config.cmake_cxx_compiler +' -print-resource-dir', shell=True).strip()
  runtime = os.path.join(resource_dir, 'lib', 'darwin',
                         'libclang_rt.asan_osx_dynamic.dylib')
  config.environment['ASAN_OPTIONS'] = \
    'detect_stack_use_after_return=1'
  config.environment['DYLD_INSERT_LIBRARIES'] = runtime

# Build dotest command.
dotest_cmd = [config.dotest_path, '-q']
dotest_cmd.extend(config.dotest_args_str.split(';'))

# We don't want to force users passing arguments to lit to use `;` as a
# separator. We use Python's simple lexical analyzer to turn the args into a
# list.
if config.dotest_lit_args_str:
  dotest_cmd.extend(shlex.split(config.dotest_lit_args_str))

# Load LLDB test format.
sys.path.append(os.path.join(config.lldb_src_root, "lit", "Suite"))
import lldbtest

# testFormat: The test format to use to interpret tests.
config.test_format = lldbtest.LLDBTest(dotest_cmd)
